package com.yunhe.device.controller.base;

import com.github.stuxuhai.jpinyin.PinyinException;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.exception.UniqueConstraintsException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.device.domain.base.DeviceType;
import com.yunhe.device.model.base.*;
import com.yunhe.device.service.base.EquipmentTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName EquipmentTypeController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/15 13:23
 * @Version 1.0
 **/
@Api(value = "EquipmentType", description = "设备类型维护", tags = {"Base_EquipmentType"})
@RestController
@RequestMapping("/types/equipmentType")
public class EquipmentTypeController {
    @Autowired
    private EquipmentTypeService equipmentTypeService;

    /**
     * 新增设备类型
     * @param equipmentTypeBo 设备类型对象
     */
    @ApiOperation("新增设备类型")
    @RequestMapping(method = RequestMethod.POST)
    public ResultObject<DeviceType> createEquipmentType(@RequestBody EquipmentTypeBo equipmentTypeBo)
            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException, PinyinException {
        DeviceType newEquipmentType = equipmentTypeService.createEquipmentType(equipmentTypeBo);
        return new ResultObject<>(newEquipmentType);
    }

    /**
     * 查询设备类型列表
     * @param equipmentTypeQueryCondition 设备类型对象
     */
    @ApiOperation("查询后台设备类型列表")
    @RequestMapping(value = "/getEquipmentTypeByCondition",method = RequestMethod.POST)
    public ResultObject<List<EquipmentTypeVo>> getEquipmentTypeByCondition(@RequestBody EquipmentTypeQueryCondition equipmentTypeQueryCondition) {
        Iterable<EquipmentTypeVo> results  = equipmentTypeService.getEquipmentTypeByCondition(equipmentTypeQueryCondition);
        return new ResultObject(results);
    }

    /**
     * 查询设备类型列表
     * @param equipmentTypeQueryCondition 设备类型对象
     */
    @ApiOperation("查询前台设备类型列表")
    @RequestMapping(value = "/getFrontEquipmentTypeByCondition",method = RequestMethod.POST)
    public ResultObject<List<EquipmentTypeVo>> getFrontEquipmentTypeByCondition(@RequestBody EquipmentTypeQueryCondition equipmentTypeQueryCondition) throws ArgumentErrorException {
        Iterable<EquipmentTypeVo> results  = equipmentTypeService.getFrontEquipmentTypeByCondition(equipmentTypeQueryCondition);
        return new ResultObject(results);
    }

    /**
     * 查询设备类型详情
     * @param id 设备类型id
     */
    @ApiOperation("查询设备类型详情")
    @RequestMapping(value = "/getEquipmentTypeById",method = RequestMethod.GET)
    public ResultObject<EquipmentTypeVo> getEquipmentTypeById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id) throws ObjectNotFoundException {
        EquipmentTypeVo EquipmentTypeVo = equipmentTypeService.getEquipmentTypeById(id);
        return new ResultObject<>(EquipmentTypeVo);
    }

    /**
     * 查询设备类型查询绑定点号类型
     * @param id 设备类型id
     */
    @ApiOperation("查询设备类型查询绑定点号类型")
    @RequestMapping(value = "/getAnlogTypeById",method = RequestMethod.GET)
    public ResultObject<AnlogTypeVo> getAnlogTypeById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id,
                                                              @ApiParam(value = "page",required = true) @RequestParam(value = "page") int page,
                                                              @ApiParam(value = "size",required = true) @RequestParam(value = "size") int size) throws ObjectNotFoundException {
        Iterable<AnlogTypeVo> anlogTypeVos = equipmentTypeService.getAnlogTypeById(id, page,size);
        return new ResultObject(anlogTypeVos);
    }

    /**
     * 根据id删除设备类型
     * @param id 设备类型对象
     */
    @ApiOperation("根据后台id删除设备类型")
    @RequestMapping(value = "/deleteEquipmentTypeById",method = RequestMethod.POST)
    public ResultObject<Void> deleteEquipmentTypeById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id) throws ArgumentErrorException, ObjectNotFoundException {
        equipmentTypeService.deleteEquipmentTypeById(id);
        return new ResultObject<>();
    }

    /**
     * 根据id删除设备类型
     * @param id 设备类型对象
     */
    @ApiOperation("根据前台id删除设备类型")
    @RequestMapping(value = "/deleteFrontEquipmentTypeById",method = RequestMethod.POST)
    public ResultObject<Void> deleteFrontEquipmentTypeById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id) throws ArgumentErrorException, ObjectNotFoundException {
        equipmentTypeService.deleteFrontEquipmentTypeById(id);
        return new ResultObject<>();
    }

    /**
     * 修改设备类型信息
     * @param equipmentTypeBo 设备类型对象
     */
    @ApiOperation("修改设备类型信息")
    @PostMapping(value = "/updateEquipmentType")
    public ResultObject<DeviceType> updateEquipmentType(@RequestBody EquipmentTypeBo equipmentTypeBo) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException, PinyinException {
        DeviceType newEquipmentType = equipmentTypeService.updateEquipmentType(equipmentTypeBo);
        return new ResultObject<>(newEquipmentType);
    }

    /**
     * 修改设备类型信息
     * @param equipmentTypeBo 设备类型对象
     */
    @ApiOperation("修改前台设备类型信息")
    @PostMapping(value = "/updateFrontEquipmentType")
    public ResultObject<DeviceType> updateFrontEquipmentType(@RequestBody EquipmentTypeBo equipmentTypeBo) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException, PinyinException {
        DeviceType newEquipmentType = equipmentTypeService.updateFrontEquipmentType(equipmentTypeBo);
        return new ResultObject<>(newEquipmentType);
    }

    /**
     * 设备类型禁用恢复
     * @param statusVo 设备类型对象
     */
    @ApiOperation("设备类型禁用恢复")
    @PostMapping(value = "/updateEquipmentTypeStauts")
    public ResultObject<Void> updateEquipmentTypeStauts(@RequestBody StatusVo statusVo) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        equipmentTypeService.updateEquipmentTypeStauts(statusVo);
        return new ResultObject<>();
    }

    /**
     * 根据设备类型查询设备类型列表
     */
    @ApiOperation("查询设备类型列表")
    @GetMapping (value = "/getEquipmentTypeByEquipName")
    public ResultObject<List<DeviceType>> getEquipmentType() throws ArgumentErrorException {
        List<DeviceType> newEquipmentTypes = equipmentTypeService.getEquipmentType();
        return new ResultObject<>(newEquipmentTypes);
    }
}
